// DatabaseTask.h
#ifndef DATABASETASK_H
#define DATABASETASK_H

#include <QRunnable>
#include <QObject>
#include <QString>
#include <QVariant>
#include <QVector>
#include <QMap>
#include <QSqlDatabase>

// 继承QObject是为了使用信号槽机制
class DatabaseTask : public QObject, public QRunnable
{
    Q_OBJECT

public:
    explicit DatabaseTask(const QString& sql, const QVariantMap& params, const QString& type, QObject* parent = nullptr);
    void run() override;
    void insertData(QSqlDatabase& db);
    void findData(QSqlDatabase& db);
    void setOperationType(const QString& type);
    QString& getOperationType();
signals:
    void finished(const QStringList& results);
    void error(const QString& errorMessage);

private:
    QString sql;
    QString operationType;
    QVariantMap parameters;
};

#endif // DATABASETASK_H
